// leaderPerson/pages/leagueMember/leagueMember.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        type: 1,
        time: 1,
        page: 1,
        list: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        this.getBase();
        this.getMemberUnder();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        this.getMemberUnder();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    chooseType: function(e) {
        this.setData({
            type: e.currentTarget.dataset.type,
            page: 1
        });
        this.getMemberUnder();
    },
    chooseTime: function(e) {
        this.setData({
            time: e.currentTarget.dataset.time,
            page: 1
        });
        this.getMemberUnder();
    },
    getMemberUnder: function() {
        let _this = this;
        let {page: page, type: type, time: time} = _this.data;
        var params = {
            page: page,
            type: type,
            time: time
        };
        common.request({
            endpoint: "My/leader_under/member-under",
            method: "post",
            data: params,
            success: res => {
                var list = res.extra;
                list = page == 1 ? list : list.concat(_this.data.list);
                this.setData({
                    list: list,
                    page: page + 1
                });
            }
        });
    },
    //全局基础配置信息
    getBase: function(openid) {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                that.setData({
                    leaderName: res.extra.leader_title ? res.extra.leader_title : "团长",
                    sleep_on: res.extra.sleep_on
                });
            }
        });
    }
});